<template>
	<view class="container">
		<!-- 实名认证 -->
		<view v-if="type == 1" class="form-container">
			<text class="page-title">实名认证</text>

			<view class="form-group">
				<text class="form-label">姓名</text>
				<view class="input-wrapper">
					<input class="form-input" v-model="requestParam.realName" placeholder="请输入真实姓名" />
				</view>
			</view>

			<view class="form-group">
				<text class="form-label">身份证号码</text>
				<view class="input-wrapper">
					<input class="form-input" v-model="requestParam.idCardNo" placeholder="请输入身份证号码" maxlength="18" />
				</view>
			</view>

			<!-- <view class="form-group">
        <text class="form-label">此身份证登记的手机号</text>
        <view class="input-wrapper">
          <input class="form-input" v-model="requestParam.phone" placeholder="请输入手机号" />
        </view>
      </view> -->

			<button class="submit-button" @click="userIdentify">提交认证</button>
		</view>

		<!-- 绑定微信 -->
		<view v-else-if="type == 2" class="form-container">
			<text class="page-title">绑定微信</text>

			<view class="form-group">
				<text class="form-label">微信号</text>
				<view class="input-wrapper">
					<input class="form-input" v-model="requestParam.weixin" placeholder="请输入微信号" />
				</view>
			</view>

			<button class="submit-button" @click="userBindWeixin">提交绑定</button>
		</view>

		<!-- 绑定手机号 -->
		<view v-else-if="type == 3" class="form-container">
			<text class="page-title">绑定手机号</text>

			<view class="form-group">
				<text class="form-label">手机号</text>
				<view class="input-wrapper">
					<input class="form-input" v-model="requestParam.phone" placeholder="请输入手机号" />
				</view>
			</view>

			<view class="form-group">
				<text class="form-label">验证码</text>
				<view class="code-group">
					<view class="input-wrapper code-input">
						<input class="form-input" v-model="requestParam.code" placeholder="输入验证码" maxlength="6" />
					</view>
					<button class="code-button" @click="sendSms">获取验证码</button>
				</view>
			</view>

			<button class="submit-button" @click="userBindPhone">提交绑定</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				requestParam: {
					realName: '',
					idCardNo: '',
					phone: '',
					code: '',
					weixin: ''
				}
			}
		},
		onLoad(options) {
			this.type = options.type;
		},
		methods: {
			userIdentify() {
				//实名认证
				this.$Request.postFormHost(this.$Api.userIdentify, this.requestParam).then(res => {
					if (res.status == 0) {
						uni.showToast({
							icon: 'success',
							title: '认证成功'
						});
						uni.navigateBack();
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			userBindWeixin() {
				//绑定微信
				this.$Request.postFormHost(this.$Api.bindWx, this.requestParam).then(res => {
					if (res.status == 0) {
						uni.showToast({
							icon: 'success',
							title: '绑定成功'
						});
						uni.navigateBack();
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			userBindPhone() {
				//绑定手机号
				this.$Request.postFormHost(this.$Api.bindPhone, this.requestParam).then(res => {
					if (res.status == 0) {
						uni.showToast({
							icon: 'success',
							title: '绑定成功'
						});
						uni.navigateBack();
					} else
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
				})
			},
			sendSms() {
				if (!this.requestParam.phone) {
					uni.showToast({
						icon: 'none',
						title: '请输入手机号'
					});
					return;
				};
				//发送验证码
				this.$Request.postFormHost(this.$Api.sendMsg, this.requestParam).then(res => {
					if (res.status == 0) {
						uni.showToast({
							icon: 'success',
							title: '发送成功'
						});
					} else
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
				})
			},
		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		min-height: 100vh;
		width: 100%;
		background: linear-gradient(180deg, #FFFFFF 0%, #E6F0FF 50%, #CCE0FF 100%);
		padding: 30rpx;
		box-sizing: border-box;
	}

	.form-container {
		width: 90%;
		max-width: 680rpx;
		background-color: rgba(255, 255, 255, 0.9);
		border-radius: 20rpx;
		box-shadow: 0 8rpx 30rpx rgba(0, 85, 255, 0.15);
		padding: 40rpx 30rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}

	.page-title {
		font-size: 36rpx;
		font-weight: bold;
		color: #0055CC;
		margin-bottom: 60rpx;
		position: relative;
		padding-bottom: 16rpx;
	}

	.page-title::after {
		content: '';
		position: absolute;
		width: 60rpx;
		height: 6rpx;
		background: linear-gradient(90deg, #0055CC, #66A3FF);
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		border-radius: 3rpx;
	}

	.form-group {
		width: 100%;
		margin-bottom: 30rpx;
	}

	.form-label {
		display: block;
		color: #0055CC;
		font-weight: 500;
		font-size: 28rpx;
		margin-bottom: 12rpx;
	}

	.input-wrapper {
		background-color: #F0F7FF;
		border: 1rpx solid #CCE0FF;
		border-radius: 8rpx;
		padding: 6rpx 20rpx;
		width: 100%;
		box-sizing: border-box;
	}

	.form-input {
		height: 70rpx;
		font-size: 28rpx;
		color: #333333;
		width: 100%;
		box-sizing: border-box;
	}

	.code-group {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		width: 100%;
	}

	.code-input {
		flex: 1;
		margin-right: 20rpx;
	}

	.code-button {
		background-color: #E6F0FF;
		color: #0055CC;
		border: 1rpx solid #CCE0FF;
		border-radius: 8rpx;
		font-size: 24rpx;
		padding: 0 20rpx;
		height: 80rpx;
		line-height: 70rpx;
		white-space: nowrap;
	}

	.submit-button {
		width: 50%;
		background: linear-gradient(135deg, #0066FF 0%, #0055CC 100%);
		color: white;
		border: none;
		border-radius: 8rpx;
		font-size: 30rpx;
		font-weight: 500;
		margin-top: 40rpx;
		padding: 16rpx 0;
	}
</style>